<!--
描述：课程管理列表
开发人：yyp
开发日期：2019/06/22
-->

<template lang="pug">
  keep-alive
    kalix-table(bizKey="course" title='课程列表' ref="kalixTable"
    v-bind:tableFields="tableFields"
    v-bind:targetURL="courseURL"
    v-bind:bizDialog="courseDialog"
    v-bind:btnList="courseBtnList"
    v-bind:customTableTool="customTableTool"
    v-bind:toolbarBtnList="toolbarBtnList"
    bizSearch="courseSearch")
</template>

<script type="text/ecmascript-6">
  import {CourseURL} from '../../config.toml'
  import {courseConfigBtnList} from './config'
  import KalixTable from '../../../../../components/corelib/components/common/baseTable'
  import {ON_REFRESH_DATA} from '@/components/corelib/components/common/event.toml'
  export default {
    name: 'kalix-mooc-courselist',
    components: {KalixTable},
    data() {
      return {
        // courseURL: CourseURL + '/getCourse',
        courseURL: CourseURL + '/getAllCourse',
        tableFields: [
          // {prop: 'dname', label: '院系'},
          // {prop: 'gname', label: '课程类别'},
          {prop: 'uname', label: '授课教师'},
          {prop: 'name', label: '课程名称'},
          {prop: 'classHour', label: '课时'},
          {prop: 'credit', label: '学分'},
          {prop: 'audit', label: '审核'},
          {prop: 'plays', label: '播放量'},
          {prop: 'teacherintroduce', label: '教师简介'}
        ],
        courseDialog: [
          {id: 'add', dialog: 'CourseAdd'},
          {id: 'edit', dialog: 'CourseEdit'},
          {id: 'view', dialog: 'CourseView'}
        ],
        courseBtnList: courseConfigBtnList,
        toolbarBtnList: [
          {id: 'add', isShow: true, title: '添加', icon: 'icon-pinleizengjia', isPermission: true}
        ],
        customTableTool(row, btnId, that) {
          if (btnId === 'audit') {
            let warnInfo = '确定要' + (row.audit === '禁止' ? '通过' : '禁止') + '该条信息吗？'
            that.$confirm(warnInfo, '警告', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              return this.$http.request({
                method: 'PUT',
                url: CourseURL + '/' + row.id,
                params: {},
                data: {
                  id: row.id,
                  audit: row.audit === '禁止' ? '通过' : '禁止',
                  classHour: row.classHour,
                  credit: row.credit,
                  did: row.did,
                  gid: row.gid,
                  introduction: row.introduction,
                  name: row.name,
                  photo: row.photo,
                  points: row.points,
                  uid: row.uid
                }
              }).then((res) => {
                console.log(res)
                this.$KalixMessage.processResult(res)
                this.$KalixEventBus.$emit(ON_REFRESH_DATA)
              })
            })
          }
        }
      }
    }
  }
</script>

<style scoped lang="stylus">

</style>
